package Iterator;

import ObjectList.ProductList;

import java.util.List;

public class ProductIterator implements Iterator {
    private ProductList productList;
    private List products;
    private int cursor1 = 0;
    private int cursor2 = 0;
    public ProductIterator(ProductList productList) {
        this.productList = productList;
        products = productList.getObjects();
        cursor1 = products.toArray().length-1;
        cursor2 = products.toArray().length-1;
    }
    @Override
    public void next() {
        cursor1++;
    }

    @Override
    public boolean isLast() {
        return cursor1 == cursor2;
    }

    @Override
    public void previous() {
        if(!isFirst()){
            cursor1--;
        }
    }

    @Override
    public boolean isFirst() {
        return cursor1 == 0;
    }

    @Override
    public Object getNextItem() {
        int cursor = cursor1;
        return products.get(++cursor);
    }

    @Override
    public Object getPreviousItem() {
        int cursor = cursor1;
        return products.get(--cursor);
    }
}
